import javax.swing.*;
import java.awt.event.*;
public class homework5 {
    public static class SimpleEventDemo extends JFrame{
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        public SimpleEventDemo() {
            this.setTitle("GUI");
            this.setSize(300,200);
            this.setVisible(true);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JButton jbtOK=new JButton("OK");//创建按钮
            setLayout(new FlowLayout());
            add(jbtOK);

            ActionListener listener=new OKListener();
            jbtOK.addActionListener(listener);

        }

        private void setLayout(FlowLayout flowLayout) {
        }

       

    }
    static class  OKListener implements ActionListener{

        @Override
        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            System.out.println("OK is clicked!");

        }
        
    }
       public static void main(String[] args) {
     
           JFrame frame=new SimpleEventDemo();
           frame.setLocationRelativeTo(null);
           frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           frame.setVisible(true);
           
       }
}
